package com.aaa.stock.controller.prod;

import com.aaa.entity.Medicines;
import com.aaa.entity.Producer;
import com.aaa.stock.service.prod.ProdcerService;
import com.aaa.stock.vo.ProducerVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/stock/prod/prod")
public class StockProdController {

    @Autowired
    private ProdcerService prodcerService;

    @PostMapping("prodList/{currentPage}/{pageSize}")
    public Result<IPage<Producer>> prodList(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody ProducerVo producerVo
    ){
        return prodcerService.findByListtion(currentPage,pageSize,producerVo);
    }
    //删除
    @DeleteMapping("deleteProdByIds/{producterIds}")
    public Result<Map<String,Object>> deleProd(@PathVariable Long producterIds){
        return prodcerService.deletPro(producterIds);
    }
    //添加
    @PostMapping("addProd")
    public Result addProd(@RequestBody Producer producer){
        prodcerService.saveOrUpdate(producer);
        return new Result(2000,"添加成功");
    }
    //批量删
    @PostMapping("delAll")
    public Result delAll(@RequestBody List<Producer> producers){
        producers.forEach((Producer prod)->{
            boolean b =prodcerService.removeById(prod.getProducerId());
        });
        return new Result(2000,"成功");
    }
    //查生产厂家
    @GetMapping("selectAllProdName")
    public Result<List<Producer>> selectAllProdName(){

        return prodcerService.selectAllProdName();
    }
}
